package com.blaze.framework.core.util.uitls;

import com.blaze.framework.core.util.exception.CheckedException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.Nullable;

import java.util.Objects;

/**
 * 断言工具类
 *
 * @author created by Zhou Zongbo on 2025/5/29.
 */
public class AssertUtil {
    private AssertUtil() {

    }

    /**
     * 判断boolean是true, 不是true则抛异常
     * @param expression expression
     * @param message message
     */
    public static void isTrue(boolean expression, String message) {
        if (Boolean.FALSE.equals(expression)) {
            throw new CheckedException(message);
        }
    }

    /**
     * 判断boolean是false, 不是false则抛异常
     * @param expression expression
     * @param message message
     */
    public static void isFalse(boolean expression, String message) {
        isTrue(Boolean.TRUE.equals(expression), message);
    }

    /**
     * 判断字符不是空, 为空则抛异常
     * @param s s
     * @param message message
     */
    public static void isNotBlank(CharSequence s, String message) {
        isTrue(StringUtils.isNotBlank(s), message);
    }

    /**
     * 判断object是null, 不是null则抛异常
     * @param object object
     * @param message message
     */
    public static void isNull(@Nullable Object object, String message) {
        isTrue(Objects.isNull(object), message);
    }

    /**
     * 判断object不是null, 是null则抛异常
     * @param object object
     * @param message message
     */
    public static void notNull(@Nullable Object object, String message) {
        isTrue(Objects.nonNull(object), message);
    }
}
